;(function () {
  window.hlSelectUi = function (flag,type) {
    var upFlag = flag || false;

    // 处理列表的展示方式
    $(document).on('click', '.select-ul span', function (event) {
      if ($(this).siblings('ul').children().length !== 0) {
        $('.select-ul ul').hide()
        $(this).siblings('ul').show();
      }

      var scrollTop = document.body.scrollTop;

      if (upFlag) {
        if (document.body.clientHeight - document.documentElement.clientHeight < scrollTop) {
          $('.select-ul ul').css({
            top: 'auto',
            bottom: '100%',
            'border-top': '1px solid #ddd'
          });
        }
        if (document.body.clientHeight - document.documentElement.clientHeight >= scrollTop) {
          $('.select-ul ul').css({
            top: '32px',
            bottom: 'auto',
            'border-top': '0'
          });
        }
        if (document.body.clientHeight - document.documentElement.clientHeight == '-20') {
          $('.select-ul ul').css({
            top: '32px',
            bottom: 'auto',
            'border-top': '0'
          });
        }
      }
      event.stopPropagation()
    });

    // 展示选中列表项名字和属性
    $(document).on('click', '.select-ul ul li', function (e) {
      $(this).parents('.select-ul').find('span').text($(this).text());
      $('.select-ul ul').hide();
      var datas = $(this).data();
      if (datas) {
        for (var item in datas) {
          $(this).parents('.select-ul').find('span').attr('data-' + item, datas[item]);
        }
      }
      e.stopPropagation()
    });
    // 点击非选中框处下拉框隐藏
    $(document).on('click', function (event) {
      $('.select-ul').find('ul').hide()
      event.stopPropagation()
    });
    if (!type) return;
    // 下拉框内项目内容超过一定长度时hover展示完整信息
    $(document).on('mouseenter','.select-ul ul li',function (e) {
      var $self = $(this);
      var txt = $self.text();
      var l = $self.offset().left;
      var t = $self.offset().top;
      var w = $self.outerWidth();
      var h = $self.outerHeight();

      if($self.children('input').length !== 0)return
      // 下拉框内字数超过14个时且不是账号有tip展示
      if(txt.length > 14 && isNaN(Number(txt))){
        $('body').append('<i class="select-qm-show">' + txt + '</i>');
        var mesw = $('.hllayer-tips').outerWidth();
        var left = l;
        var top = t + h ;
        $('.select-qm-show').css({
          top: top,
          left: left,
          display:'block'
        })
      }
    })
    $(document).on('mouseleave','.select-ul ul li',function (e) {
      $('.select-qm-show').remove();
    })
  }

}())
